package com.md.api.common.utils;

import java.security.MessageDigest;

public class SHA512Util {

    public static String encode(String inputString){
        try {
            // 创建SHA-512 MessageDigest对象
            MessageDigest digest = MessageDigest.getInstance("SHA-512");

            // 执行加密操作
            byte[] hashBytes = digest.digest(inputString.getBytes("UTF-8"));

            // 将字节转换成十六进制字符串
            StringBuilder hexString = new StringBuilder();
            for (byte b : hashBytes) {
                String hex = Integer.toHexString(0xff & b);
                if (hex.length() == 1) hexString.append('0');
                hexString.append(hex);
            }
            System.out.println(hexString.toString());
            return hexString.toString();
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
